home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-24 | 3.6 KB | 96 lines |
- import java.awt.*;
- import java.awt.image.*;
- import java.net.*;
- import java.applet.*;
-
- public class OldShellGame extends Applet {
- static int time=50; // Number of timing loops between key frames
- static int numframes=8; // Number of key frames in the animation
- boolean running=false; // Switch to turn animation on and off
-
- /** The keyframe locations of images */
- static int movesX0[] = {0,0,0,284,0,142,284,142,142};
- static int movesY0[] = {50,50,50,176,50,176,50,176,50};
- static int movesX1[] = {142,142,142,142,284,0,0,0,284};
- static int movesY1[] = {50,50,50,176,50,176,50,176,50};
- static int movesX2[] = {284,126,284,0,142,284,142,284,0};
- static int movesY2[] = {50,176,50,176,50,176,50,176,50};
- static int movesX3[] = {142,142,300,16,158,300,158,300,16};
- static int movesY3[] = {192,192,66,192,66,192,66,192,66};
-
- /** The current location of images */
- int left[] = {0,142,284,142};
- int top[] = {50,50,50,192};
-
- /** The images for the shell game */
- Image shell;
- Image stone;
-
- /** Initialize the applet. Resize and load images. */
- public void init() {
- stone = getImage(getCodeBase(), "gem.gif");
- shell = getImage(getCodeBase(), "walnut.gif");
- }
-
- /** Paint it. */
- public void paint(Graphics g) {
- int count = 0;
- int curframe = 1;
- Dimension d = size();
- g.fillRect(0,0,d.width,d.height);
- g.drawImage(stone, left[3], top[3], this);
- g.drawImage(shell, left[0], top[0], this);
- g.drawImage(shell, left[1], top[1], this);
- g.drawImage(shell, left[2], top[2], this);
- if(running) {
- while(count < time*numframes) {
- left[0] = movesX0[curframe-1] +
- ((movesX0[curframe]-movesX0[curframe-1])*(count % time)/time);
- top[0]=movesY0[curframe-1] +
- ((movesY0[curframe]-movesY0[curframe-1])*(count % time)/time);
- left[1]=movesX1[curframe-1] +
- ((movesX1[curframe]-movesX1[curframe-1])*(count % time)/time);
- top[1]=movesY1[curframe-1] +
- ((movesY1[curframe]-movesY1[curframe-1])*(count % time)/time);
- left[2]=movesX2[curframe-1] +
- ((movesX2[curframe]-movesX2[curframe-1])*(count % time)/time);
- top[2]=movesY2[curframe-1] +
- ((movesY2[curframe]-movesY2[curframe-1])*(count % time)/time);
- left[3]=movesX3[curframe-1] +
- ((movesX3[curframe]-movesX3[curframe-1])*(count % time)/time);
- top[3]=movesY3[curframe-1] +
- ((movesY3[curframe]-movesY3[curframe-1])*(count % time)/time);
- g.fillRect(0,0,d.width,d.height);
- if(count<time || count>=time*numframes) {
- g.drawImage(stone, left[3], top[3], this);
- }
- g.drawImage(shell, left[0], top[0], this);
- g.drawImage(shell, left[1], top[1], this);
- g.drawImage(shell, left[2], top[2], this);
- count++;
- if(count%time==0 && curframe<numframes) {
- curframe++;
- }
- Delay(200,count);
- }
- }
- running=false;
- }
-
- /** The user has clicked in the applet. Start the animation */
- public boolean mouseUp(Event evt, int x, int y) {
- running=true;
- left[3] = 142;
- top[3] = 192;
- repaint();
- return true;
- }
-
- public void Delay(long d,int count) {
- long x=0,y=0;
- for(x=0;x<d;x++) {
- y++;
- }
- }
- }
-